package cn.bdqn.service.impl;

import cn.bdqn.mapper.ProductMapper;
import cn.bdqn.pojo.Product;
import cn.bdqn.service.ProductService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ProductServiceImpl implements ProductService {
    @Resource
    ProductMapper productMapper;
    @Override
    public IPage<Product> getProductsByPage(String prodName, String prodType, String prodBatch, Integer pageNo, Integer pageSize) {
        //组装分页条件
        Page<Product> page=new Page<>(pageNo,pageSize);
        //组装过滤条件 动态sql
        QueryWrapper<Product> qw=new QueryWrapper();
        qw.like(prodName!=null&&!"".equals(prodName), "prod_name",prodName);
        qw.like(prodType!=null&&!"".equals(prodType),"prod_type",prodType);
        qw.like(prodBatch!=null&&!"".equals(prodBatch),"prod_batch",prodBatch);
        //调用分页方法
        IPage<Product> productPage=productMapper.selectPage(page, qw);
        //返回分页对象
        return productPage;
    }

}
